﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment3.Objects
{
    class ReflectSphere
    {
        private Model _spehere;
        private Effect _reflectEffect;
        private TextureCube _skyboxTexture;

        public ReflectSphere(Model sphere, Effect reflectEffect, TextureCube skyboxTexture)
        {
            _spehere = sphere;
            _reflectEffect = reflectEffect;
            _skyboxTexture = skyboxTexture;
        }

        public void DrawModelWithEffect(Matrix world, Matrix view, Matrix projection, Vector3 cameraPos)
        {
            foreach (ModelMesh mesh in _spehere.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = _reflectEffect;
                    _reflectEffect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
                    _reflectEffect.Parameters["View"].SetValue(view);
                    _reflectEffect.Parameters["Projection"].SetValue(projection);
                    _reflectEffect.Parameters["SkyboxTexture"].SetValue(_skyboxTexture);
                    _reflectEffect.Parameters["CameraPosition"].SetValue(cameraPos);
                    _reflectEffect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(world * mesh.ParentBone.Transform)));
                }
                mesh.Draw();
            }
        }
    }
}
